import 'package:flutter_09_game/base/controller/base_controller.dart';
import 'package:flutter_09_game/utils/log/utils_log.dart';
import 'package:url_launcher/url_launcher.dart';
import 'models/exchange_item_model.dart';

class HomeDownloadCenterLogic extends BaseController {
  List<ExchangeItemModel> exchangeList = [];

  @override
  void onInit() {
    super.onInit();
    _initData();
  }

  void _initData() {
    exchangeList = ExchangeItemModel.getDefaultList();
    update();
  }

  /// 打开教程链接
  Future<void> openTutorial(String url) async {
    // try {
    // clog('dasd  $url');
    final Uri uri = Uri.parse(url);
    // if (await canLaunchUrl(uri)) {
    await launchUrl(uri, mode: LaunchMode.externalApplication);
    // }
    // } catch (e) {
    //   print('打开教程链接失败: $e');
    // }
  }

  /// 打开下载链接
  Future<void> openDownload(String url) async {
    // try {
    final Uri uri = Uri.parse(url);
    // if (await canLaunchUrl(uri)) {
    await launchUrl(uri, mode: LaunchMode.externalApplication);
    // }
    // } catch (e) {
    //   print('打开下载链接失败: $e');
    // }
  }
}
